package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.pojo.LaborCharges;
import com.gxa.zhonglong.pojo.Supplier;
import com.gxa.zhonglong.service.LaborChargesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author NITRO
 */

@Api
@CrossOrigin
@RestController
@RequestMapping("/laborCharges")
public class LaborChargesController {

    @Autowired
    private LaborChargesService laborChargesService;


    @ApiOperation(value = "添加工费")
    @PostMapping("/addLaborCharges")
    public Map addLaborCharges(LaborCharges laborCharges) throws BusinessException {
        JsonResult jsonResult = new JsonResult();

        Boolean aBoolean = laborChargesService.addLaborCharges(laborCharges);
        jsonResult.setCode("1");

        return jsonResult.getDataMap();
    }


    @ApiOperation(value = "删除工费")
    @PostMapping("/deleteLaborCharges")
    public Map<String,Object> deleteGoodsWeight(@RequestBody Map<String,List<Long>> ids) throws BusinessException {
        laborChargesService.deleteLaborCharges(ids.get("ids"));
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "修改工费")
    @PostMapping("/updateLaborCharges")
    public Map updateLaborCharges(LaborCharges laborCharges) throws BusinessException {
        JsonResult jsonResult = new JsonResult();
            laborChargesService.updateLaborCharges(laborCharges);
            jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "查询工费")
    @PostMapping("/getSupplierList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码",required =true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页条数",required =true,dataType = "Integer",paramType = "query")
    })
    public Map getSupplierList(@RequestParam("page")Integer page,
                               @RequestParam("size")Integer size){


        List<LaborCharges> laborChargesList = laborChargesService.getLaborChargesList(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(laborChargesList);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }
}
